//
//  SQLDataBase.m
//  SQL面向对象数据库封装
//
//  Created by 崔博 on 2018/9/30.
//  Copyright © 2018年 崔博. All rights reserved.
//

#import "SQLDataBase.h"
#import <sqlite3.h>
@implementation SQLDataBase

// 创建db文件，并生成一个文件指针
- (instancetype)initWithFileName:(NSString *)dataBaseName
{
    if (self = [super init]) {
        self.dataName = dataBaseName;
        NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
        NSString *eocDBFile = [filePath stringByAppendingPathComponent:dataBaseName];
        
        // 如果文件不存在，就创建该文件，其配置属性是 SQLITE_OPEN_CREATE
        
        int status =  sqlite3_open_v2([eocDBFile UTF8String], &_dataBaseSql, SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE, NULL);
        
        if (status != SQLITE_OK) {
            NSLog(@"sqlite3_open_v2 fail");
        }
    }
    return self;
}

@end
